/*
New Scotland Yard is an online multiplayer adaptation
of the boardgame "Scotland Yard". Copyright (C) 2011
Massey University Software C Group 3
This program is free software: you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General
Public License along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
package nz.ac.massey.softwarec.group3.chat;
import java.util.LinkedList;
import nz.ac.massey.softwarec.group3.reverseAJAX.ReverseAJAXCall;
/**
* Chat - Class describing the InGameChat object - is compiled into Javascript by DWR for use with ReverseAJAX.
* @version 1.0 Release
* @since 1.0
* @authors Natalie Eustace | Wanting Huang | Paul Smith | Craig Spence
*/
public class InGameChat implements InGameChatInterface{
/**
* Adds message that user has posted to the chat object, and distributed to
* the users who are in the correct game to display using reverseAJAX.
* @param String text - the text of the chat message.
* @param String userName - the name of the user who sent it.
* @param String gameCreator - the creator of the game, which determines that ReverseAJAX filter.
*/
@Override
final public void addMessage(final String text, final String userName, final String gameCreator) {
if (text != null && text.trim().length() > 0) {
messages.addFirst(new Message(text, userName));
while (messages.size() > 10) {
messages.removeLast();
}
}
final ReverseAJAXCall call = new ReverseAJAXCall();
final String messageJSON = "{ \"Name\" : \"" + userName + "\", \"Message\" : \"" + text + "\" }";
call.createFilteredFunctionCall("/Software_Engineering_C/Resources/JavaServerPages/ingame.jsp", "Game", gameCreator, "addMessage", messageJSON);
}
final transient private LinkedList messages = new LinkedList();
}